<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/10 0010
 * Time: 13:14
 */
//父进程跟子进程通讯
//子进程向父进程发送消息
$msg_key = ftok(__DIR__, 'u');//注意在php创建消息队列，第二个参数会直接转成字符串，可能会导致通讯失败
$msg_queue = msg_get_queue($msg_key);
$pid = pcntl_fork();

if ($pid == 0) {
    msg_send($msg_queue, 10, '我是子进程发送的消息');
} elseif ($pid > 0) {
    msg_receive($msg_queue, 10, $msg_type, 1024, $message);
    var_dump($message);
}
